﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
        <script language="javascript" type="text/javascript">
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="/logout">[退出]</a>
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <ul id="menu">
                <li><a href="/index" class="index_on"></a></li>
                <li id="lia1"><a href="/role_list" class="role_off"></a></li>
                <li id="lia2"><a href="/admin_list" class="admin_off"></a></li>
                <li id="lia3"><a href="/fee_list" class="fee_off"></a></li>
                <li id="lia4"><a href="/account_list" class="account_off"></a></li>
                <li id="lia5"><a href="/service_list" class="service_off"></a></li>
                <li id="lia6"><a href="/bill_list" class="bill_off"></a></li>
                <li id="lia7"><a href="/report_list" class="report_off"></a></li>
                <li><a href="/userInfo" class="information_off"></a></li>
                <li><a href="/userModifyPwd" class="password_off"></a></li>
            </ul>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">            
            <div id="save_result_info" class="save_success">保存成功！</div>
            <form action="" method="" class="main_form">
                    <div class="text_info clearfix"><span>姓名：</span></div>
                    <div class="input_info">
                        <input type="text"  id="AdminName"/>
                        <span class="required">*</span>
                        <div class="validate_msg_long error_msg">20长度以内的汉字、字母、数字的组合</div>
                    </div>
                    <div class="text_info clearfix"><span>管理员账号：</span></div>
                    <div class="input_info"><input type="text" readonly="readonly" class="readonly" id="adminCode"  /></div>
                    <div class="text_info clearfix"><span>电话：</span></div>
                    <div class="input_info">
                        <input type="text" id="telephone"  />
                        <span class="required">*</span>
                        <div class="validate_msg_long error_msg">正确的电话号码格式：手机或固话</div>
                    </div>
                    <div class="text_info clearfix"><span>Email：</span></div>
                    <div class="input_info">
                        <input type="text" class="width200" id="email"/>
                        <span class="required">*</span>
                        <div class="validate_msg_medium error_msg">50长度以内，正确的 email 格式</div>
                    </div>
                    <div class="text_info clearfix"><span>角色：</span></div>
                    <div class="input_info_high">
                        <div class="input_info_scroll">
                            <ul id="ul">

                            </ul>
                        </div>
                        <span class="required">*</span>
                        <div class="validate_msg_tiny error_msg">至少选择一个</div>
                    </div>
                    <div class="button_info clearfix">
                        <input type="button" value="保存" class="btn_save" onclick="showResult();" />
                        <input type="button" value="取消" class="btn_save" onclick="location.href='/index' ; "/>
                    </div>
                </form>  
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)云科技有限公司 </span>
        </div>
    </body>
    <script src="/js/jquery-3.2.1.js"></script>
    <script>

        show();
        function show() {
            $.ajax({
                url: "/selectAllModules",
                type: "post",
                success: function (result) {

                    if (result.indexOf("角色管理") == -1) {
                        document.getElementById("lia1").style.display = "none"
                    }
                    if (result.indexOf("管理员") == -1) {
                        document.getElementById("lia2").style.display = "none"
                    }
                    if (result.indexOf("资费管理") == -1) {
                        document.getElementById("lia3").style.display = "none"
                    }
                    if (result.indexOf("账务账号") == -1) {
                        document.getElementById("lia4").style.display = "none"
                    }
                    if (result.indexOf("业务账号") ==-1) {
                        document.getElementById("lia5").style.display = "none"
                    }
                    if (result.indexOf("账单管理") ==-1) {
                        document.getElementById("lia6").style.display = "none"
                    }
                    if (result.indexOf("报表") == -1) {
                        document.getElementById("lia7").style.display = "none"
                    }


                }

            });
        }

        urlinfo = window.location.href; //获取当前页面的url
        len = urlinfo.length;//获取url的长度
        offset = urlinfo.indexOf("?");//设置参数字符串开始的位置
        parmarinfo = urlinfo.substr(offset, len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
        params = parmarinfo.split("=");//对获得的参数字符串按照“=”进行分割
        id = params[1];//得到参数值
        name = params[0];//得到参数名字

        getAllRole();

        function getAllRole() {
            $.ajax({
                url: "/findAllRole",
                type: "post",
                success: function (result) {
                    for (var i in result) {
                        var role = result[i]
                        $("#ul").append("<li><input type=checkbox name=message id='" + role.roleId + "' value= " + role.roleId + " />" + role.name + "</li>")
                    }
                    //根据roleId查role
                    getData();
                }
            })
        }

        function getData() {
            $.ajax({
                url:"selectAdminModuleById",
                data:{
                    adminId: id
                },
                success: function (result) {
                    $("#AdminName").val(result.name);
                    $("#adminCode").val(result.adminCode);
                    $("#telephone").val(result.telephone);
                    $("#email").val(result.email);

                    var roleInfoList = result.roleInfoList;
                    for (var i in roleInfoList) {
                        var role = roleInfoList[i];
                        var id = role.roleId;
                        $("#" + id + "").attr("checked", true)
                    }
                }
            })
        }

        //保存成功的提示消息
        function showResult() {

            var roles = new Array();
            $("input[name=message]").each(function (i, d) {
                if (d.checked) {
                    roles.push(d.value);
                }
            })
            if (roles.length < 1) {
                alert("您没有选中项!");
            } else {

                $.ajax({
                    url: "/updataAdmin",
                    type:"post",
                    data:{
                        adminId: id,
                        name: $("#AdminName").val(),
                        namecode: $("#adminCode").val(),
                        tel: $("#telephone").val(),
                        email: $("#email").val(),
                        roles: roles,
                    },
                    success: function (result) {
                        window.location.href= result.msg;

                    }
                })
            }
        }

    </script>
</html>
